#include <clusnet/base/DynamicBuffer.h>
#include <clusnet/base/DynamicBufferLow.h>
#include <clusnet/base/Timestamp.h>

#include <iostream>

template<typename T>
void benchmark(size_t count)
{
    const char* str = "abcdefghij";     // 10bytes
    clusnet::base::Timestamp start(clusnet::base::Timestamp::now());
    T buffer(1024);
    for (size_t i = 0; i < count; ++i)
    {
        buffer.append(str, strlen(str));
    }
    clusnet::base::Timestamp  end(clusnet::base::Timestamp::now());
    std::cout << "test append " << buffer.length() << " bytes used " << clusnet::base::timeDifference(end, start) * 1000 << "us" << std::endl;    
}

int main()
{
    std::cout << "bench dynamic buffer" << std::endl;
    benchmark<clusnet::base::DynamicBuffer>(1024 * 1024 * 50);    // 500Mb
    std::cout << "bench dynamic buffer low" << std::endl;
    benchmark<clusnet::base::DynamicBufferLow>(1024 * 1024 * 50);    // 500Mb
    return 0;
}
